import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;

public class Navigation {

    WebDriverWait wait;
    WebDriver driver;

    public Navigation(WebDriver driver) {
        this.driver = driver;
        this.wait = new WebDriverWait (driver,10);
    }
    public  Navigation(WebDriver driver, WebDriverWait wait){
        this.driver = driver;
        this.wait = wait;
    }

    public void topNavigation(String linkText, String pageTitle){

        WebElement mainMenu = driver.findElement(By.id(PageVariableValues.topNavigationBar));
        WebElement selectMenu = mainMenu.findElement(By.linkText(linkText));
        selectMenu.click();

        wait.until(titleIs(pageTitle));
    }

    public void topNavigationSub(String linkText, String nextLinkText, String pageTitle){

        WebElement mainMenu = driver.findElement(By.id(PageVariableValues.topNavigationBar));
        WebElement selectMenu = mainMenu.findElement(By.linkText(linkText));

        selectMenu.click();

        wait.until(ExpectedConditions.elementToBeClickable(By.linkText(nextLinkText)));

        WebElement subMenu = mainMenu.findElement(By.linkText(nextLinkText));
        subMenu.click();
        wait.until(titleIs(pageTitle));
    }
}
